<?php


	class SelectOrdersStock extends Connection {
		private $conn;

		public function __construct() {
			Connection::init();
			$this->conn = $this->getConnection();
		}


		public function extractStocksInOrder($id) {
			$stmt = $this->conn->prepare("	SELECT s.name, s.quantity_type, o.quantity , o.price
											FROM  order_stocks o
											join stock s on (o.stock_id = s.id)
											WHERE o.order_id =  ?");
			$stmt->bindValue(1, (int)$id, PDO::PARAM_INT);
			$stmt->execute();
			$arrStocks = $stmt->fetchall(PDO::FETCH_ASSOC);
			foreach ($arrStocks as $stock) {
				$stockOBJ = new Stock();
				$stockOBJ->setName($stock["name"]);
				$stockOBJ->setQuantity($stock["quantity_type"]);
				$stockOBJ->setOrderQuantity($stock["quantity"]);
				$stockOBJ->setPrice($stock["price"]);
				$arrayStockObj[] = $stockOBJ;
			}

			return $arrayStockObj;


		}

	}

?>